// *****************************************
// Table B4: Sample selection on observables
// *****************************************

// Writes the results as reg_selection to $resultpath/tables/

use "$outpath/database_for_reg.dta", clear

eststo clear

global instruct "tdec(3) rdec(3) auto(3) bdec (3) symbol($^a$,$^b$,$^c$) se e(r2_p) tex label nocons"

xi: reghdfe Lnland_pwc Lnpopcma Lnareacma dist_min_NEW i.cat0 spacematep spacematep2 spacematep3 spacematep4 Lnemp i.hoffice i.exports NBdiffbusiness NBdiffnaics4 NBdiffproduct Lndist_maj_air Lndist_maj_sea Lndist_stat_freight Lndist_junction if samplep==1, absorb(naics4d eruid) cluster(cmauid)

gen insample= e(sample)==1

xi: probit insample Lnemp i.hoffice i.exports i.province i.naics4d Lnpopcma Lnda_density05 if cmauid!=.&year==2017, vce(cluster cmauid)

xi: probit insample i.naics4d  if cmauid!=.&year==2017&e(sample)==1, vce(cluster cmauid)
outreg2 using "$resultpath/tables/reg_selection.xls", replace $instruct 

xi: probit insample i.naics4d i.province i.cat0  if cmauid!=.&year==2017&e(sample)==1, vce(cluster cmauid)
outreg2 using "$resultpath/tables/reg_selection.xls", append $instruct 

xi: probit insample Lnemp NBdiffbusiness NBdiffnaics4 NBdiffproduct  i.hoffice i.exports i.province i.naics4d i.cat0 if cmauid!=.&year==2017&e(sample)==1, vce(cluster cmauid)
outreg2 using "$resultpath/tables/reg_selection.xls", append $instruct 

xi: probit insample Lnemp NBdiffbusiness NBdiffnaics4 NBdiffproduct  i.hoffice i.exports i.province i.naics4d i.cat0 Lnpopcma Lnda_density05 Lndist_maj_air Lndist_maj_sea Lndist_stat_freight Lndist_junction if cmauid!=.&year==2017&e(sample)==1, vce(cluster cmauid)
outreg2 using "$resultpath/tables/reg_selection.xls", append $instruct 
